home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / tutorial / casestdy / ch17_dav / clock.dcr / 00022_Tile Parent Script.ls < prev    next >
Encoding:
Text File  |  1996-11-12  |  3.4 KB  |  94 lines

  1. property pMySprite, pMyMemNum
  2. global cBoundSprite, cGridSprite, cGridSpace, cHalfGridSpace, cGroutSprite, cTileLocList, cTileOffset, cFloatSprite, cShadowSprite, cGridHList, cGridVList, gTileTrackList, cRightEdge, cBottomEdge
  3.  
  4. on new me, mySprite, myMem
  5.   set pMySprite to mySprite
  6.   set pMyMemNum to the number of member myMem
  7.   return me
  8. end
  9.  
  10. on dragTile me
  11.   set mH to the mouseH
  12.   set mV to the mouseV
  13.   set HSTART to the locH of sprite pMySprite
  14.   set VSTART to the locV of sprite pMySprite
  15.   set spriteWidth to the width of sprite pMySprite
  16.   set spriteHeight to the height of sprite pMySprite
  17.   if (HSTART - mH) > 0 then
  18.     set H_offset to min(spriteWidth, HSTART - mH)
  19.   else
  20.     set H_offset to max(-spriteWidth, HSTART - mH)
  21.   end if
  22.   if (VSTART - mV) > 0 then
  23.     set V_offset to min(spriteHeight, VSTART - mV)
  24.   else
  25.     set V_offset to max(-spriteHeight, VSTART - mV)
  26.   end if
  27.   set the castNum of sprite cFloatSprite to pMyMemNum
  28.   set the loc of sprite cFloatSprite to the loc of sprite pMySprite
  29.   set the loc of sprite pMySprite to point(-1000, -1000)
  30.   repeat while the stillDown
  31.     set the locH of sprite cFloatSprite to the mouseH + H_offset
  32.     set the locV of sprite cFloatSprite to the mouseV + V_offset
  33.     set the locH of sprite cShadowSprite to the mouseH + H_offset + 16
  34.     set the locV of sprite cShadowSprite to the mouseV + V_offset + 16
  35.     updateStage()
  36.   end repeat
  37.   placeTile(me)
  38. end
  39.  
  40. on placeTile me
  41.   if sprite cFloatSprite within cBoundSprite then
  42.     set whichHPos to findPosNear(cGridHList, the locH of sprite cFloatSprite - cHalfGridSpace)
  43.     set whichVPos to findPosNear(cGridVList, the locV of sprite cFloatSprite - cHalfGridSpace)
  44.     set whichH to getAt(cGridHList, whichHPos)
  45.     set whichV to getAt(cGridVList, whichVPos)
  46.     slideIntoPlace(me, whichH, whichV)
  47.     set checkProp to string(whichVPos) & string(whichHPos)
  48.     setAt(gTileTrackList, pMySprite - cTileOffset, checkProp)
  49.     updateStage()
  50.     set the loc of sprite cFloatSprite to point(-1000, -1000)
  51.     set the loc of sprite cShadowSprite to point(-1000, -1000)
  52.   else
  53.     setAt(gTileTrackList, pMySprite - cTileOffset, EMPTY)
  54.     if the locH of sprite cFloatSprite > (cRightEdge - 8) then
  55.       set whichH to cRightEdge
  56.     else
  57.       if the locH of sprite cFloatSprite < -8 then
  58.         set whichH to 0
  59.       else
  60.         set whichH to the locH of sprite cFloatSprite + 8
  61.       end if
  62.     end if
  63.     if the locV of sprite cFloatSprite > (cBottomEdge - 8) then
  64.       set whichV to cBottomEdge
  65.     else
  66.       if the locV of sprite cFloatSprite < -8 then
  67.         set whichV to 0
  68.       else
  69.         set whichV to the locV of sprite cFloatSprite + 8
  70.       end if
  71.     end if
  72.     slideIntoPlace(me, whichH, whichV)
  73.   end if
  74.   puppetSound("Drop")
  75.   updateStage()
  76. end
  77.  
  78. on slideIntoPlace me, targetH, targetV
  79.   set deltaH to targetH - the locH of sprite cFloatSprite
  80.   set deltaV to targetV - the locV of sprite cFloatSprite
  81.   set deltaHS to targetH - the locH of sprite cShadowSprite
  82.   set deltaVS to targetV - the locV of sprite cShadowSprite
  83.   repeat with i = 1 to 10
  84.     set comp to 10 - i
  85.     set the locH of sprite cFloatSprite to targetH - (comp * deltaH / 10)
  86.     set the locV of sprite cFloatSprite to targetV - (comp * deltaV / 10)
  87.     set the locH of sprite cShadowSprite to targetH - (comp * deltaHS / 10)
  88.     set the locV of sprite cShadowSprite to targetV - (comp * deltaVS / 10)
  89.     updateStage()
  90.   end repeat
  91.   set the loc of sprite pMySprite to the loc of sprite cFloatSprite
  92.   updateStage()
  93. end
  94.